package com.wing.cms.dao;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.wing.common.CommonSpringJDBC;
import com.wing.common.util.PageBean;
import com.wing.cms.domain.Article_group;

@Repository
public class Article_groupDao extends CommonSpringJDBC<Article_group, String> {

	public List getArtgroupByArtId(String artId) {
		String sql = "select c.* from cms_article_group t,cms_artgroup c where t.artgroup_id=c.id and t.article_id=? ";
		return super.getSimpleJdbcTemplate().queryForList(sql,artId);
	}

	public void deleteArticle_groupByArtId(String artId) {
		String sql = "delete from cms_article_group where article_id =? ";
		super.getSimpleJdbcTemplate().update(sql, artId);
	}

	public List<Map<String, Object>> getArticle_groupByGrpIdArtId(String artgroupId, String artId) {
		String sql = "select t.* from cms_article_group t where t.artgroup_id=? and t.article_id=? ";
		Object [] objs = {artgroupId,artId};
		return super.getSimpleJdbcTemplate().queryForList(sql,objs);
	}

	public void deleteArticle_groupByArtId(String artId, String artgroupIds) {
		String sql = "delete from cms_article_group where article_id =? and artgroup_id not in ("+artgroupIds+")";
		super.getSimpleJdbcTemplate().update(sql, artId);
		
	}

	public void deleteArticle_groupByGrpIdArtIds(String grpId, String artIds) {
		String sql = "delete from cms_article_group where artgroup_id =? and article_id in ("+artIds+")";
		super.getSimpleJdbcTemplate().update(sql, grpId);
	}

	public void deleteArticle_groupByGrpId(String grpId) {
		String sql = "delete from cms_article_group where artgroup_id =? ";
		super.getSimpleJdbcTemplate().update(sql, grpId);
	}
}
